<template>
    <div class="contain-box">
        <div class="box-header">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>销售管理</el-breadcrumb-item>
                <el-breadcrumb-item to="/salesSlip" replace>销售单</el-breadcrumb-item>
                <el-breadcrumb-item>销售单详情</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="box-body">
            <div class="body-top">销售单</div>
            <div class="body-set">
                <el-input disabled v-model="addObj.customerName" placeholder="客户" style="width: 200px;margin-right: 10px"
                          size="small"></el-input>
                <el-select disabled v-model="addObj.warehousId" placeholder="请选择出库仓库" size="small"
                           style="width: 200px;margin-right: 10px">
                    <el-option disabled v-for="item in warehousList" :key="item.id" :label="item.warehousName"
                               :value="item.id"></el-option>
                </el-select>
                <el-date-picker
                        disabled
                        v-model="addObj.orderCreateTime"
                        value-format="yyyy-MM-dd"
                        size="small"
                        type="date"
                        placeholder="选择日期">
                </el-date-picker>
            </div>

            <div class="body-table">
                <el-table
                        :data="addObj.goodList"
                        size="small"
                        border
                        style="width: 100%">
                    <el-table-column
                            type="index"
                            label="序号"
                            width="100px"
                            align="center"
                    >
                    </el-table-column>
                    <el-table-column
                            prop="createTime"
                            label="订单日期"
                            align="center"
                    >
                    </el-table-column>

                    <el-table-column
                            prop="name"
                            label="商品名称"
                            align="center"
                    >
                    </el-table-column>
                    <el-table-column
                            prop="attributeContent"
                            label="规格型号"
                            align="center"
                    >
                    </el-table-column>
                    <el-table-column
                            prop="inventory"
                            label="数量"
                            align="center"
                    >
                    </el-table-column>
                    <el-table-column
                            prop="goodMeasurementUnit.name"
                            label="单位"
                            align="center"
                    >
                    </el-table-column>
                    <el-table-column
                            prop="price"
                            label="销售单价(元)"
                            align="center"
                    >
                    </el-table-column>


                </el-table>
            </div>
            <div class="body-message">
                <p style="font-size: 16px">收货信息 : </p>
                <div class="message-box">
                    <div class="message-son">
                        <span>收货人 : </span> <span>{{addObj.consignee?addObj.consignee:'无'}}</span>
                    </div>
                    <div class="message-son">
                        <span>联系电话 : </span> <span>{{addObj.phone?addObj.phone:'无'}}</span>
                    </div>
                    <div class="message-son">
                        <span>收货地址 : </span> <span>{{addObj.receiveGoodAddr?addObj.receiveGoodAddr:'无'}}</span>
                    </div>


                </div>
            </div>
            <div class="body-set">
                <el-input disabled v-model="addObj.discountRate" placeholder="折扣率%"
                          style="width: 200px;margin-right: 10px" size="small"></el-input>
                <el-input  v-model="addObj.discountMoney" disabled placeholder="折扣金额"
                          style="width: 200px;margin-right: 10px" size="small"></el-input>
                <el-select disabled v-model="addObj.settlementId" placeholder="请选择结算方式" size="small"
                           style="width: 200px;margin-right: 10px">
                    <el-option disabled v-for="item in settlementList" :key="item.id" :label="item.settlementName"
                               :value="item.id"></el-option>
                </el-select>
            </div>
            <div class="body-set">
                <el-input disabled v-model="addObj.remarks" placeholder="请输入订单备注" type="textarea" style="width: 50%" :rows="5"
                          resize="none"
                          size="small"></el-input>
            </div>
        </div>
        <div class="box-submit">
            <div class="submit-left">
                <p>总计金额: <span>￥{{addObj.discountMoney+addObj.actualReceiptMoney}}</span></p>
                <p>实收金额: <span>￥{{addObj.actualReceiptMoney}}</span></p>
            </div>
            <div>
                <el-button @click="goBack" type="primary" size="small" style="background-color: #1abc9c">返 回
                </el-button>
            </div>
        </div>
    </div>
</template>

<script>
    import VDistpicker from 'v-distpicker'

    export default {
        name: "AddSalesOrder",
        components: {VDistpicker},
        data() {
            return {
                pageObj: {
                    pageIndex: 1,
                    pageSize: 5,
                    name: null
                },
                total: 0,
                placeholders: {
                    province: '请选择省份',
                    city: '请选择市区',
                    area: '请选择县城或区',
                },
                tableData: [],
                settlementList: [],
                addObj: {
                    orderCreateTime: null,
                    customerName: null,
                    warehousId: null,
                    goodId: [],
                    consignee: null,
                    phone: null,
                    receiveGoodAddr: null,
                    discountRate: null,
                    discountMoney: 0,
                    actualReceiptMoney: 0,
                    settlementId: null,
                    orderRemarks: null
                },
                warehousList: [],
            }
        },
        created() {
            this.getAllSettlement()
            this.getAllWarehous()
            this.findById(this.$route.query.id)
        },
        methods: {
            findById(id){
                this.axios.get('/salesOrder/findById?id='+id).then(res=>{
                    if(res.data.code===200){
                        this.addObj = res.data.data
                    }
                })
            },
            //查询全部结算方式
            getAllSettlement() {
                this.axios.get('/settlement/findAll').then(res => {
                    if (res.data.code === 200) {
                        this.settlementList = res.data.data
                    }
                })
            },
            //查询全部仓库
            getAllWarehous() {
                this.axios.get('/warehous/findAll').then(res => {
                    if (res.data.code === 200) {
                        this.warehousList = res.data.data
                    }
                })
            },
            goBack() {
                this.$router.replace('/salesSlip')
            },
            onChangeProv(e) {
                console.log("省", e);
                this.select.c = null
                this.select.a = null
                if (e.value === '请选择省份') {
                    this.select.p = null
                    return false
                }
                this.select.p = e.value
            },
            onChangeCity(e) {
                console.log("市", e);
                this.select.a = null
                if (e.value === '请选择市区') {
                    this.select.c = null
                    return false
                }
                this.select.c = e.value
            },
            onChangeArea(e) {
                console.log("县", e);
                if (e.value === '请选择县城或区') {
                    this.select.a = null
                    return false
                }
                this.select.a = e.value
            },
            handleSelectionChange(val) {
                console.log(val)
                this.chooseList = val
            }
        }
    }
</script>

<style scoped lang="less">
    .contain-box {
        width: 100%;
        height: 100%;

        /deep/ .distpicker-address-wrapper {
            select {
                width: 32% !important;
                padding: 0px 10px !important;
                height: 35px !important;
                font-size: 12px !important;
                line-height: 35px !important;
                border-radius: 5px;
            }
        }

        .dialog-box {
            width: 100%;
        }

        .dialog-page {
            margin-top: 20px;
            width: 100%;
            display: flex;
            align-items: center;
            justify-content: flex-end;

            /deep/ .el-pagination.is-background .el-pager li:not(.disabled).active {
                background-color: #1abc9c;
            }
        }

        /deep/ .el-dialog__body {
            padding: 10px 20px;
        }

        .box-header {
            width: 100%;
            height: 50px;
            display: flex;
            align-items: center;
            margin-bottom: 10px;
        }

        .box-body {
            width: 100%;
            border-radius: 5px;
            padding: 20px;
            box-sizing: border-box;
            box-shadow: 0 0 5px 0 #e4e4e4;

            .body-top {
                width: 100%;
                height: 50px;
                text-align: center;
                line-height: 50px;
                border-bottom: 1px solid #e4e4e4;
                font-size: 20px;
                color: #666;
            }

            .body-set {
                margin-top: 20px;
                width: 100%;
                display: flex;
                align-items: center;
                justify-content: flex-start;
            }

            .body-add {
                margin-top: 20px;
                width: 100%;
            }

            .body-table {
                margin-top: 20px;
                width: 100%;
            }

            .body-message {
                margin-top: 20px;
                width: 100%;

                .message-box {
                    margin-top: 20px;
                    display: flex;
                    align-items: center;
                    cursor: pointer;

                    .message-img {
                        margin-left: 20px;
                        width: 20px;
                        height: 20px;
                    }

                    .message-son {
                        margin-right: 15px;
                        font-size: 14px;
                    }
                }
            }
        }

        .box-submit {
            margin-top: 20px;
            width: 100%;
            border-radius: 5px;
            padding: 20px;
            box-sizing: border-box;
            display: flex;
            align-items: center;
            justify-content: space-between;
            box-shadow: 0 0 5px 0 #e4e4e4;

            .submit-left {
                display: flex;
                font-size: 16px;

                p {
                    margin-right: 20px;

                    span {
                        color: red;
                        font-weight: bold;
                    }
                }
            }
        }
    }
</style>
